package rwt.server.handlers.web;

import rwt.server.*;
import rwt.server.RailroadMessages.LocoSndMsg;
import rwt.server.WebMessages.SetTrainMute;
import rwt.server.core.*;
import rwt.server.railroad.*;

public class SetTrainMuteHandler extends MessageHandler<SetTrainMute>
{
	@Override
	public void handle(SetTrainMute message, IConnection source) throws Exception
	{
		Train t = RailServer.getTrainManager().getTrainById(message.trainId);
		int slot = t.getVirtualSlotNum();
		LocoSndMsg railMsg = new LocoSndMsg(slot, t.getCloseNextSwitch(), t.getThrowNextSwitch(), message.mute);
		
		RailroadSystem system = t.isEmergency() ? RailServer.getRailroadServer() : RailServer.getController();
		system.write(railMsg);
	}
}
